<?php
/**
 * 必须通过安全验证才能进行操作的ACTION,
 * 
 * 在进行安全验证过程中如果通过验证将会触发authorized_success事件,反之触发authorized_failure事件
 * 
 * @author Leo 2010-11-19
 *
 */
abstract class AuthAction extends Action {	
	/**
	 * 
	 * 执行exec前的安全检验
	 * 
	 * @uses authorized_failure filter the args are $request, $response
	 * @param IRequest $request
	 * @param Response $response
	 * @param Ioc $ioc
	 * @return boolean
	 */
	public function beforeExec($request, $response, $ioc) {
		$I = whoami ();
		if ($I->authorized) {
			return true;
		} else {
			$this->jump = isset ( $this->jump ) && ! empty ( $this->jump ) ? $this->jump : $this->getJumpUrl ( $request, $response, $ioc );
			fire ( 'authorized_failure', $request, $response );
			$xajax = isset ( $_SERVER ["HTTP_X_AJAX_TYPE"] );
			if ($xajax) {
				@header ( 'X-AJAX-REDIRECT: ' . $this->jump );
				$response->close ( true );
			}
			return false;
		}
	}
}